/*
 *
 *name:zhang-lingfan
 *
 *功能：求出最优SPARE_CAPACITY
 *
 */

#include <iostream>
#include "vector.h"
#include <cstdlib>

using namespace std;

void f(int N)//构造求出最优SPARE_CAPACITY的函数
{
    float mincount = 999;
    float mini = 0;
    float m = 999;
    ///
    for (int i = 1;i < N + 1;i++)
    {
        float allcount = 0.0;
        float all = 0.0;
        Vector<int> vector;
        vector.sparechange(i);//令vector的SPARE_CAPACITY值为i
        for (int j = 0;j < 10000;j++)
        {
            int n = (rand() % N) + 1;//产生1到N的随机数n
            for (int k = 0;k < n;k++)
            {
                vector.push_back(1);//在vector后添加1
            }
            allcount += vector.countout();
            all += float(vector.size()) / float(vector.capacity());
        }
        if (mincount > allcount / 10000)
        {
            mincount = allcount / 10000;
            mini = i;
            m = all / 10000;
        }
    }
    cout << "when N = " << N << "," << "the best SPARE_CAPACITY is:" << mini << endl;
    
}


int main()
{
  //分别测试N=50，100,150,200的情况。
    f(50);
    f(100);
    f(150);
    f(200);
};
